package com.icebartech.base.modules.common.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.icebartech.base.modules.common.dto.VerifyCodeDTO;
import com.icebartech.base.modules.common.service.VerifyCodeService;
import com.icebartech.core.controller.BaseController;
import com.icebartech.core.vo.BaseData;
import com.icebartech.core.vo.RespJson;
import com.icebartech.core.vo.ResponseData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"验证码相关接口"})
@RestController
@RequestMapping(value = "/base/verifyCode", produces = "application/json;charset=UTF-8")
public class VerifyCodeController extends BaseController {

	@Autowired
	private VerifyCodeService verifyCodeService;
	
	@ApiOperation(value = "获取字母验证码", notes = "登录时获取字母验证码")
	@PostMapping(value = "/randomCode")
	public RespJson<BaseData<VerifyCodeDTO>> randomCode(){
		RespJson<BaseData<VerifyCodeDTO>> respJson = getFailRtnMap("未知错误");
		ResponseData<VerifyCodeDTO> codeResp = verifyCodeService.randowVerifyCode();
		if(codeResp.isSusscess()) {
			BaseData<VerifyCodeDTO> baseData = new BaseData<>(codeResp.getData());
			respJson = getSuccessRtnMap("获取验证码成功!", baseData);
		}else {
			respJson = getFailRtnMap(codeResp.getMessage());
		}
		return respJson;
	}
}
